package com.rbac.api.mybatis.mapper;


import com.rbac.api.mybatis.entityCus.CusAdRoleLinkedEntity;
import com.rbac.api.mybatis.entityCus.CusRoleHaveUsersMemberEntity;
import com.rbac.api.mybatis.sqlProvider.AdminRolesUsersSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;


@Mapper
public interface AdminRolesUsersMapper {



    ///角色关联的管理员数据入库
    @InsertProvider(type=AdminRolesUsersSqlProvider.class, method="insertManyRolesUsersDataSelective")
    int insertManyRolesUsersDataSelective(@Param("list") List<CusAdRoleLinkedEntity> record);



    ///根据角色编号获取拥有的管理员成员
    @Select({
            "select\n",
            "aru.role_no,aru.user_no,au.user_name\n",
            "from admin_roles_users as aru\n",
            "LEFT JOIN admin_users as au on aru.user_no=au.user_no\n",
            "where aru.role_no = #{roleNo,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="role_no", property="roleNo", jdbcType= JdbcType.VARCHAR),
            @Result(column="user_no", property="userNo", jdbcType= JdbcType.VARCHAR),
            @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR)
    })
    List<CusRoleHaveUsersMemberEntity> selectHaveUsersMemberByRoleNoMapper(@Param("roleNo") String roleNo);


    ///根据角色编号删除关联的管理员数据
    @Delete({
            "DELETE FROM `admin_roles_users`\n",
            "where role_no = #{roleNo,jdbcType=VARCHAR}\n"
    })
    int deleteDataByRoleNoMapper(@Param("roleNo") String roleNo);


}